package com.example.tests;

import java.io.FileReader;
import java.util.Properties;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.log4testng.Logger;

import com.example.fw.ApplicationManager;

public class TestBase {
	
	protected Logger log = Logger.getLogger(getClass());
	
	protected ApplicationManager app;
	

	@BeforeClass
	@Parameters({"configFile"})
	public void setUp(@Optional String configFile) throws Exception {
		if (configFile == null)
			configFile = System.getProperty("configFile");
		if (configFile == null)
			configFile = System.getenv("configFile");
		if (configFile == null)
			configFile = "application.properties";
		
		Properties pro = new Properties();
		pro.load(new FileReader(configFile));
		log.info("setup is starting...");
		app = ApplicationManager.getInstance();
		app.setProperties(pro);
		log.info("setUp is end...");
	}

	@AfterTest
	public void tearDown() throws Exception {
		log.info("tearDown is start...");
		ApplicationManager.getInstance().stop();
		log.info("tearDown is end...");
	}

}
